package com.huawei.hianalytics.f.f;

import android.os.Build;
import android.text.TextUtils;
import com.huawei.hianalytics.a.b;
import com.huawei.hianalytics.a.c;
import com.huawei.hianalytics.h.e;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

final class n implements l {
    private static n a;

    private n() {
    }

    public static l a() {
        return b();
    }

    private String a(String str, String str2) {
        return "oper".equals(str) ? "{url}/common/hmshioperqrt".replace("{url}", str2) : "maint".equals(str) ? "{url}/common/hmshimaintqrt".replace("{url}", str2) : "diffprivacy".equals(str) ? "{url}/common/common2".replace("{url}", str2) : "";
    }

    private Map<String, String> a(String str, String str2, String str3) {
        Map<String, String> hashMap = new HashMap();
        hashMap.put("App-Id", b.f());
        hashMap.put("App-Ver", b.g());
        hashMap.put("Sdk-Name", "hianalytics");
        hashMap.put("Sdk-Ver", "2.1.4.312");
        hashMap.put("Device-Type", Build.MODEL);
        hashMap.put("servicetag", str);
        com.huawei.hianalytics.g.b.b("HiAnalytics/event", "sendData RequestId : %s", str2);
        hashMap.put("Request-Id", str2);
        Map i = c.i(str, str3);
        if (i != null) {
            for (Entry entry : i.entrySet()) {
                hashMap.put(entry.getKey(), entry.getValue());
            }
        }
        return hashMap;
    }

    private static synchronized l b() {
        l lVar;
        synchronized (n.class) {
            if (a == null) {
                a = new n();
            }
            lVar = a;
        }
        return lVar;
    }

    public boolean a(byte[] bArr, String str, String str2, String str3) {
        com.huawei.hianalytics.h.c a;
        Object c = c.c(str2, str);
        Map a2 = a(str2, str3, str);
        String str4 = "";
        com.huawei.hianalytics.g.b.b("NetHandler", "send data body size : " + bArr.length);
        if ("preins".equals(str) && b.j().length > 0) {
            a = e.a().a(bArr, a2, "preload_url_tag");
        } else if (TextUtils.isEmpty(c)) {
            com.huawei.hianalytics.g.b.c("NetHandler", "No report address,TAG : %s,TYPE: %s ", str2, str);
            return false;
        } else {
            a = com.huawei.hianalytics.h.b.a(a(str, c), bArr, a2);
        }
        com.huawei.hianalytics.g.b.b("HiAnalytics/event", "events PostRequest sendevent TYPE : %s, TAG : %s, resultCode: %d ,reqID:" + str3, str, str2, Integer.valueOf(a.a()));
        return a.a() == 200;
    }
}
